﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Laos;

namespace Pollux.Interpreter.Venus2.Aspects
{
	[Serializable]
	[AttributeUsage(AttributeTargets.Property)]
	public class BitmaskValidatorAspekt : OnMethodBoundaryAspect
	{
		public int Min = int.MinValue;
		public int Max = int.MaxValue;
		public int MaskMin = int.MinValue;
		public int MaskMax = int.MaxValue;

		public override void  OnEntry(MethodExecutionEventArgs eventArgs)
		{
			base.OnEntry ( eventArgs );

			Object[] args = eventArgs.GetArguments();
			if (args == null)
			{
				return;
			}

			//string propertys			
			if ( args[0] is string )
			{				
				int value = Int32.Parse ( (string)args[0]);

				if (	( value < Min && value > MaskMin )
					||	( value > Max )
					||	( value < MaskMax )
				  )
				{
					throw new ArgumentException ( "Invalid Value " + ( string )args[0] );
				}
			}
		}
	}
}
